import Mock from 'mockjs2'
import { builder, getQueryParameters, pageData } from '../util'
import userDatas from '@/assets/data/userJson'
import applyDatas from '@/assets/data/applyJson'

const customerPage = (options) => {
  const params = getQueryParameters(options)
  console.log(params)
  const result = pageData(userDatas, params)
  return builder(result)
}

const customerApplyList = (options) => {
  const strs = options.url.split('/')
  const customerId = strs[strs.length - 1]
  console.log(customerId)
  const applyList = searchCustomerApplyList(customerId)
  return builder(applyList)
}

function searchCustomerApplyList (customerId) {
  return applyDatas.filter((value) => {
    if (String(value['userId']) === String(customerId)) {
      return value
    }
  })
}

Mock.mock(/\/user\/page/, 'get', customerPage)
Mock.mock(/\/stock\/user\/[^\s]+/, 'get', customerApplyList)
